package com.hxzy.service.impl;

import com.hxzy.entity.TbExpressCompany;
import com.hxzy.mapper.TbExpressCompanyMapper;
import com.hxzy.service.TbExpressCompanyService;
import com.hxzy.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TbExpressCompanyServiceImpl implements TbExpressCompanyService {
    @Override
    public TbExpressCompany selectByPrimaryKey(Integer id) {
        TbExpressCompany tbExpressCompany=null;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbExpressCompanyMapper mapper = session.getMapper(TbExpressCompanyMapper.class);
            tbExpressCompany=mapper.selectByPrimaryKey(id);
        }
        return tbExpressCompany;
    }

    @Override
    public boolean insert(TbExpressCompany record) {
        int i=0;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbExpressCompanyMapper mapper = session.getMapper(TbExpressCompanyMapper.class);
            i=mapper.insert(record);
            session.commit();//增删改都要提交事务
        }
        return i>0;
    }

    @Override
    public boolean updateByPrimaryKey(TbExpressCompany record) {
        int i=0;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbExpressCompanyMapper mapper = session.getMapper(TbExpressCompanyMapper.class);
            i=mapper.updateByPrimaryKey(record);
            session.commit();//增删改都要提交事务
        }
        return i>0;
    }

    @Override
    public boolean updateByPrimaryKeySelective(TbExpressCompany record) {
        int i=0;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbExpressCompanyMapper mapper = session.getMapper(TbExpressCompanyMapper.class);
            i=mapper.updateByPrimaryKey(record);
            session.commit();
        }
        return i>0;
    }

    @Override
    public List<TbExpressCompany> search() {
        List<TbExpressCompany> search=null;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbExpressCompanyMapper mapper = session.getMapper(TbExpressCompanyMapper.class);
            search = mapper.search();
            session.commit();
        }
        return search;
    }

    @Override
    public List<TbExpressCompany> searchByCondition(TbExpressCompany tbExpressCompany) {
        List<TbExpressCompany> list;
        try (SqlSession session= MybatisUtil.getSqlSessionFactory().openSession()){
            TbExpressCompanyMapper mapper = session.getMapper(TbExpressCompanyMapper.class);
            list = mapper.searchByCondition(tbExpressCompany);
        }
        return list;
    }
}
